package com.id2216.fridge.data;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class FridgeItem 
{

	private int id;
    private String name;
    private Date expire;
    private String pic;
    private int status;
    
 
    public FridgeItem(){}
 
    public FridgeItem(int id ,String name, Date expire , String pic , int status) 
    {
        super();
        this.setId(id);
        this.setName(name);
        this.setExpire(expire);
        this.setPic(pic);
        this.setStatus(status);
    }
 
    
    //getters & setters
    
    public String getName()
    {
    	return this.name;
    }
    public void setName(String name)
    {
    	this.name = name;
    }

	public Date getExpire() {
		return expire;
	}

	public void setExpire(Date date) {
		this.expire = date;
	}

	
	public String getPic() {
		return pic;
	}

	public void setPic(String pic) {
		this.pic = pic;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String getExpireDay()
	{
		Date newerDate = new Date();
		int diffInDays = (int)( (newerDate.getTime() - expire.getTime()) 
                / (1000 * 60 * 60 * 24) );
		
		if( diffInDays > 0 )
			return "Expired";
		if( diffInDays == 0 )
			return "Today";
		else if (diffInDays == -1 )
			return "1 day";
		else
			diffInDays = 0 - diffInDays;
				
		return Integer.toString(diffInDays) + " days";
	}
	
	public boolean isExpire()
	{
		Date newerDate = new Date();
		int diffInDays = (int)( (newerDate.getTime() - expire.getTime()) 
                / (1000 * 60 * 60 * 24) );
		
		if( diffInDays > 0 )
			return true;
		
		return false;
	}
	
	@SuppressLint("SimpleDateFormat")
	public String getExpireString()
	{
	      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
	      String format = dateFormat.format(this.getExpire());
		return format;
	}
	
	@SuppressLint("SimpleDateFormat")
	public void setExpireString(String dateString)
	{
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        Date date = new Date();
     	try {
			date = dateFormat.parse(dateString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
     	this.setExpire(date);

	}

}
